package org.jeecg.modules.exPingbiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Maps;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.exPingbiao.domain.form.ExPingbiaoExpertRejectForm;
import org.jeecg.modules.exPingbiao.entity.*;
import org.jeecg.modules.exPingbiao.mapper.*;
import org.jeecg.modules.exPingbiao.service.IExPingbiaoExpertDetailService;
import org.jeecg.modules.exPingbiao.service.IExPingbiaoExpertService;
import org.jeecg.modules.exPingbiao.service.IExPingbiaoExpertStageService;
import org.jeecg.modules.exPingbiao.service.IExTbcompanyScoreService;
import org.jeecg.modules.exPingbiao.vo.*;
import org.jeecg.modules.exProject.entity.ExSection;
import org.jeecg.modules.exProject.mapper.ExSectionMapper;
import org.jeecg.modules.exTender.entity.ExTenderList;
import org.jeecg.modules.exTender.service.IExTenderListService;
import org.jeecg.modules.exTenderFile.service.IExZbwjConformanceReviewDetailService;
import org.jeecg.modules.exTenderFile.service.IExZbwjScoreStandardDetailService;
import org.jeecg.modules.exZbwjBidEvaluationConfig.domain.entity.ExZbwjBidEvaluationConfig;
import org.jeecg.modules.exZbwjBidEvaluationConfig.domain.entity.ExZbwjBidEvaluationItem;
import org.jeecg.modules.exZbwjBidEvaluationConfig.mapper.ExZbwjBidEvaluationConfigMapper;
import org.jeecg.modules.exZbwjBidEvaluationConfig.mapper.ExZbwjBidEvaluationItemMapper;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysUserMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Description: 评标
 * @Author: jeecg-boot
 * @Date: 2024-11-09
 * @Version: V1.0
 */
@Service
public class ExPingbiaoExpertServiceImpl extends ServiceImpl<ExPingbiaoExpertMapper, ExPingbiaoExpert> implements IExPingbiaoExpertService {

    @Autowired
    private ExPingbiaoExpertMapper exPingbiaoExpertMapper;
    @Autowired
    private ExPingbiaoExpertDetailMapper exPingbiaoExpertDetailMapper;
    //评分标准-评审项
    @Autowired
    private IExZbwjScoreStandardDetailService iExZbwjScoreStandardDetailService;
    //符合性审查项 -评审项
    @Autowired
    private IExZbwjConformanceReviewDetailService iExZbwjConformanceReviewDetailService;
    @Autowired
    private ExSectionMapper exSectionMapper;
    @Autowired
    private IExPingbiaoExpertDetailService exPingbiaoExpertDetailService;
    @Autowired
    private IExPingbiaoExpertStageService exPingbiaoExpertStageService;
    @Autowired
    private ExPingbiaoSectionExpertConfigMapper expertConfigMapper;
    @Autowired
    private ExPingbiaoExpertStageMapper exPingbiaoExpertStageMapper;
    @Autowired
    private ExPingbiaoExpertStageDetailMapper exPingbiaoExpertStageDetailMapper;
    @Autowired
    private ExPingbiaoSectionExpertConfigMapper exPingbiaoSectionExpertConfigMapper;
    @Autowired
    private ExZbwjBidEvaluationConfigMapper evaluationConfigMapper;
    @Autowired
    private ExZbwjBidEvaluationItemMapper evaluationItemMapper;
    @Autowired
    private SysUserMapper sysUserMapper;

    @Autowired
    private IExTenderListService exTenderListService;
    @Autowired
    private IExTbcompanyScoreService exTbcompanyScoreService;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveMain(ExPingbiaoExpert exPingbiaoExpert, List<ExPingbiaoExpertDetail> exPingbiaoExpertDetailList) {
        ExSection exSection = exSectionMapper.selectById(exPingbiaoExpert.getBidSectionId());
        if (null != exSection) {
            exPingbiaoExpert.setBidSectionCode(exSection.getBidSectionCode());
        }
        ExZbwjBidEvaluationItem evaluationItem = evaluationItemMapper.selectById(exPingbiaoExpert.getBusinessId());
        if (null != evaluationItem) {
            exPingbiaoExpert.setRealBusinessId(evaluationItem.getBusinessId());
        }

        exPingbiaoExpertMapper.insert(exPingbiaoExpert);
        if (exPingbiaoExpertDetailList != null && exPingbiaoExpertDetailList.size() > 0) {
            for (ExPingbiaoExpertDetail entity : exPingbiaoExpertDetailList) {
                //外键设置
                entity.setPingbiaoExpertId(exPingbiaoExpert.getId());
                entity.setBusinessType(exPingbiaoExpert.getBusinessType());
                exPingbiaoExpertDetailMapper.insert(entity);
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMain(ExPingbiaoExpert exPingbiaoExpert, List<ExPingbiaoExpertDetail> exPingbiaoExpertDetailList) {
        exPingbiaoExpertMapper.updateById(exPingbiaoExpert);


        //2.子表数据重新插入
        if (exPingbiaoExpertDetailList != null && exPingbiaoExpertDetailList.size() > 0) {
            for (ExPingbiaoExpertDetail entity : exPingbiaoExpertDetailList) {
                //1.先删除子表数据
                exPingbiaoExpertDetailMapper.deleteByMainIdAndBusinessId(exPingbiaoExpert.getId(), entity.getBusinessId());
                //外键设置
                entity.setPingbiaoExpertId(exPingbiaoExpert.getId());
                entity.setBusinessType(exPingbiaoExpert.getBusinessType());
                exPingbiaoExpertDetailMapper.insert(entity);
            }
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delMain(String id) {
        exPingbiaoExpertDetailMapper.deleteByMainId(id);
        exPingbiaoExpertMapper.deleteById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delBatchMain(Collection<? extends Serializable> idList) {
        for (Serializable id : idList) {
            exPingbiaoExpertDetailMapper.deleteByMainId(id.toString());
            exPingbiaoExpertMapper.deleteById(id);
        }
    }

    @Override
    @Transactional
    public void save(ExPingbiaoExpertParam exPingbiaoExpertParam) {
        if ("符合性审查项".equals(exPingbiaoExpertParam.getBusinessType())) {

        }
        if ("评分标准".equals(exPingbiaoExpertParam.getBusinessType())) {

        }
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<ExPingbiaoExpert> query = new LambdaQueryWrapper<ExPingbiaoExpert>()
                .eq(ExPingbiaoExpert::getBidSectionId, exPingbiaoExpertParam.getBidSectionId())
                .eq(ExPingbiaoExpert::getBusinessType, exPingbiaoExpertParam.getBusinessType())
                .eq(ExPingbiaoExpert::getBusinessId, exPingbiaoExpertParam.getBusinessId())
                .eq(ExPingbiaoExpert::getTenderListId, exPingbiaoExpertParam.getTenderListId())
                .eq(ExPingbiaoExpert::getIdCard, sysUser.getId());
        ExPingbiaoExpert exPingbiaoExpert = this.getOne(query);
        if (exPingbiaoExpert == null) {
            exPingbiaoExpert = new ExPingbiaoExpert();
            exPingbiaoExpert.setExpertId(sysUser.getId());
            exPingbiaoExpert.setIdCard(sysUser.getId());
            exPingbiaoExpert.setCompleteStatus("1");
            BeanUtils.copyProperties(exPingbiaoExpertParam, exPingbiaoExpert);
            this.saveMain(exPingbiaoExpert, exPingbiaoExpertParam.getDetailList());
        } else {
            exPingbiaoExpert.setCompleteStatus("1");
            this.updateMain(exPingbiaoExpert, exPingbiaoExpertParam.getDetailList());
        }

        // 默认设置当前的评标节点
        exPingbiaoExpertStageService.saveRecord(exPingbiaoExpertParam.getBidSectionId(), exPingbiaoExpertParam.getBusinessType(), exPingbiaoExpertParam.getBusinessId());
    }

    @Override
    public ExPingbiaoExpertPage getInfo(String tenderListId, String businessType, String businessId,String expertId) {

        LambdaQueryWrapper<ExPingbiaoExpert> query = new LambdaQueryWrapper<ExPingbiaoExpert>()
                .eq(ExPingbiaoExpert::getTenderListId, tenderListId)
                .eq(ExPingbiaoExpert::getBusinessType, businessType)
                .eq(ExPingbiaoExpert::getBusinessId, businessId)
                .eq(ExPingbiaoExpert::getIdCard, expertId);
        ExPingbiaoExpert exPingbiaoExpert = this.getOne(query);
        if (exPingbiaoExpert == null) {
            return null;
        }
        ExPingbiaoExpertPage exPingbiaoExpertPage = new ExPingbiaoExpertPage();
        BeanUtils.copyProperties(exPingbiaoExpert, exPingbiaoExpertPage);
        List<ExPingbiaoExpertDetail> exPingbiaoExpertDetailList = exPingbiaoExpertDetailService.selectByMainId(exPingbiaoExpert.getId());
        exPingbiaoExpertPage.setExPingbiaoExpertDetailList(exPingbiaoExpertDetailList);
        return exPingbiaoExpertPage;
    }


    @Override
    public ExPingbiaoExpertItemDetailVO getItemList(String tenderListId, String businessType, String businessId) {
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        LambdaQueryWrapper<ExPingbiaoExpert> query = new LambdaQueryWrapper<ExPingbiaoExpert>()
                .eq(ExPingbiaoExpert::getTenderListId, tenderListId)
                .eq(ExPingbiaoExpert::getBusinessType, businessType)
                .eq(ExPingbiaoExpert::getBusinessId, businessId)
                .eq(ExPingbiaoExpert::getIdCard, sysUser.getId());
        ExPingbiaoExpert exPingbiaoExpert = this.getOne(query);
        if (exPingbiaoExpert == null) {
            return null;
        }
        ExPingbiaoExpertItemDetailVO exPingbiaoExpertPage = new ExPingbiaoExpertItemDetailVO();
        List<ExPingbiaoExpertDetail> exPingbiaoExpertDetailList = exPingbiaoExpertDetailService.selectByMainId(exPingbiaoExpert.getId());
        exPingbiaoExpertPage.setItemList(exPingbiaoExpertDetailList);
        exPingbiaoExpertPage.setCompleteStatus(exPingbiaoExpert.getCompleteStatus());
        return exPingbiaoExpertPage;
    }

    @Override
    public List<ExPingbiaoExpert> selectByExpertIdAndBusinessIdList(String expertId, List<String> businessIdList) {
        if (CollectionUtils.isEmpty(businessIdList)) {
            return Lists.newArrayList();
        }
        return exPingbiaoExpertMapper.selectByExpertIdAndBusinessIdList(expertId, businessIdList);
    }

    @Override
    @Transactional
    public Result<String> nextBusiness(String bidSectionId) {
        ExPingbiaoExpertStage exPingbiaoExpertStage = exPingbiaoExpertStageMapper.selectBySectionId(bidSectionId);
        if (null == exPingbiaoExpertStage){
            return Result.error("还未设置评分，不能前往下一步");
        }
        if(exPingbiaoExpertStage.getIsSummary() == 0) {//非汇总下一步
            // 查询所有的投标人
            List<ExTenderList> tenderLists = exTenderListService.queryBySectionId(bidSectionId);
            tenderLists = tenderLists.stream().filter(item -> Boolean.FALSE.equals(item.getRejectFlag())).collect(Collectors.toList());
            // 非当前审查节点下 存在不符合的投标人的评标记录
            List<ExPingbiaoExpert> pingbiaoRejectExpertList = exPingbiaoExpertMapper.selectRejectByExBusinessId(bidSectionId, exPingbiaoExpertStage.getBusinessId(),"3");
            //不符合的投标人list
            List<String> failTenderListIdList = pingbiaoRejectExpertList.stream().map(ExPingbiaoExpert::getTenderListId).distinct().collect(Collectors.toList());
            //当前审查节点下的所有评标记录
            List<ExPingbiaoExpert> list = exPingbiaoExpertMapper.selectBySectionIdAndBusinessId(bidSectionId, exPingbiaoExpertStage.getBusinessId());
            // 获取评分专家
            List<ExPingbiaoSectionExpertConfig> expertConfigList = exPingbiaoSectionExpertConfigMapper.selectByProjectAndSectionId(null, exPingbiaoExpertStage.getBidSectionId());
            // 获取专家名称
            List<String> expertUserIdList = expertConfigList.stream().map(ExPingbiaoSectionExpertConfig::getExpertId).collect(Collectors.toList());
            List<SysUser> sysUserList = sysUserMapper.selectBatchIds(expertUserIdList);
            Map<String, String> sysUserNameMap = sysUserList.stream().collect(Collectors.toMap(SysUser::getId, SysUser::getUsername));
            for (ExPingbiaoSectionExpertConfig expertConfig : expertConfigList) {
                List<ExPingbiaoExpert> expertList = list.stream().filter(e -> Objects.equals(expertConfig.getExpertId(), e.getExpertId())).collect(Collectors.toList());
                String expertUserName = sysUserNameMap.get(expertConfig.getExpertId());
                if (CollectionUtils.isEmpty(expertList)) {
                    // 获取当前专家的名称，修改提示：xx专家还未进行设置，不能进行下一步
                    return Result.error(String.format("%s专家还未设置不能前往下一步", expertUserName));
                }
                for (ExTenderList tenderList : tenderLists) {
                    long count = expertList.stream().filter(e -> Objects.equals(tenderList.getId(), e.getTenderListId())).count();
                    if (count == 0) {
                        return Result.error(String.format("%s专家未设置%s不能前往下一步", expertUserName, tenderList.getBidderName()));
                    }
                }
            }
        } else {//汇总
            ExPingbiaoExpertStageDetail exPingbiaoExpertStageDetail = exPingbiaoExpertStageDetailMapper.selectBySectionIdAndBusinessId(bidSectionId, exPingbiaoExpertStage.getBusinessId(), exPingbiaoExpertStage.getBusinessType());
            if (exPingbiaoExpertStageDetail == null) {
                return Result.error("未填写汇总意见不能前往下一步");
            }
        }
        return exPingbiaoExpertStageService.updateRecordToNext(bidSectionId);
    }

    @Override
    public Result<String> backEdit(ExPingbiaoExpertRejectForm form) {
        exPingbiaoExpertMapper.backEdit(form.getId(), form.getRejectRemark(), "3");
        return Result.ok();
    }

    @Override
    public Result<ExPingbiaoExpertConfigVO> config(String projectId, String sectionId, String expertId) {
        List<ExPingbiaoSectionExpertConfig> expertConfigList = expertConfigMapper.selectByProjectAndSectionId(null, sectionId);
        ExPingbiaoExpertConfigVO configVO = new ExPingbiaoExpertConfigVO();
        if (CollectionUtils.isEmpty(expertConfigList)) {
            configVO.setGroupFlag(Boolean.FALSE);
        } else {
            Optional<ExPingbiaoSectionExpertConfig> filterList = expertConfigList.stream().filter(e -> Objects.equals(expertId, e.getExpertId()) && BooleanUtils.isTrue(e.getGroupFlag())).findFirst();
            if (filterList.isPresent()) {
                configVO.setGroupFlag(Boolean.TRUE);
            }
        }
        ExPingbiaoExpertStage exPingbiaoExpertStage = exPingbiaoExpertStageMapper.selectBySectionId(sectionId);
        if (null != exPingbiaoExpertStage) {
            configVO.setBusinessId(exPingbiaoExpertStage.getBusinessId());
            configVO.setIsSummary(exPingbiaoExpertStage.getIsSummary());
            ExPingbiaoExpertStageDetail exPingbiaoExpertStageDetail = exPingbiaoExpertStageDetailMapper.selectBySectionIdAndBusinessId(sectionId, configVO.getBusinessId(), exPingbiaoExpertStage.getBusinessType());
            if (exPingbiaoExpertStageDetail != null) {
                configVO.setCompleteStatus(exPingbiaoExpertStageDetail.getCompleteStatus() == 1);
            }
        }
        ExZbwjBidEvaluationConfig evaluationConfig = evaluationConfigMapper.selectByBidSectionId(sectionId);
        if (null == evaluationConfig) {
            configVO.setLastFlag(Boolean.TRUE);
        } else {
            List<ExZbwjBidEvaluationItem> evaluationItemList = evaluationItemMapper.selectByMainIdList(com.google.common.collect.Lists.newArrayList(evaluationConfig.getId()));
            for (int i = 0; i < evaluationItemList.size(); i++) {
                ExZbwjBidEvaluationItem evaluationItem = evaluationItemList.get(i);
                if (Objects.equals(evaluationItem.getId(), exPingbiaoExpertStage != null ? exPingbiaoExpertStage.getBusinessId() : "") && i == evaluationItemList.size() - 1 && 1 == exPingbiaoExpertStage.getIsSummary()) {
                    configVO.setLastFlag(Boolean.TRUE);
                }
            }
        }
        //configVO.setAllCompletedFlag(getAllCmpleted(sectionId,expertId));
        configVO.setAllCompletedFlag(BooleanUtils.isTrue(configVO.getLastFlag()) && BooleanUtils.isTrue(configVO.getCompleteStatus()));
        return Result.ok(configVO);
    }

    @Override
    public Result<List<ExPingbiaoExpertRecordVO>> queryRecord(String sectionId, String tenderListId) {
        List<ExPingbiaoSectionExpertConfig> expertConfigList = expertConfigMapper.selectByProjectAndSectionId(null, sectionId);
        ExPingbiaoExpertStage exPingbiaoExpertStage = exPingbiaoExpertStageMapper.selectBySectionId(sectionId);
        // 查询专家设置
        List<ExPingbiaoExpert> list = Lists.newArrayList();
        Map<String,ExPingbiaoExpert> completeStatusMap = Maps.newHashMap();
        if(null != exPingbiaoExpertStage){
            list = exPingbiaoExpertMapper.selectBySectionIdAndBusinessIdTenderListId(sectionId, exPingbiaoExpertStage.getBusinessId(), tenderListId);
            completeStatusMap = list.stream().collect(Collectors.toMap(ExPingbiaoExpert::getExpertId, Function.identity()));
        }
        Map<String, String> sysUserMap = Maps.newHashMap();
        if (CollectionUtils.isNotEmpty(expertConfigList)) {
            List<String> idList = expertConfigList.stream().map(ExPingbiaoSectionExpertConfig::getExpertId).collect(Collectors.toList());
            List<SysUser> sysUserList = sysUserMapper.selectBatchIds(idList);
            sysUserMap = sysUserList.stream().collect(Collectors.toMap(SysUser::getId, SysUser::getUsername));
        }

        List<ExPingbiaoExpertRecordVO> voList = Lists.newArrayList();
        for (ExPingbiaoSectionExpertConfig e : expertConfigList) {
            ExPingbiaoExpertRecordVO exPingbiaoExpertRecordVO = new ExPingbiaoExpertRecordVO();
            exPingbiaoExpertRecordVO.setName(sysUserMap.get(e.getExpertId()));
            ExPingbiaoExpert exPingbiaoExpert = completeStatusMap.get(e.getExpertId());
            if (null != exPingbiaoExpert) {
                exPingbiaoExpertRecordVO.setId(exPingbiaoExpert.getId());
                exPingbiaoExpertRecordVO.setCompleteStatus(exPingbiaoExpert.getCompleteStatus());
            }

            voList.add(exPingbiaoExpertRecordVO);
        }

        return Result.ok(voList);
    }

    @Override
    public Result<List<ExPingbiaoExpertDetail>> queyrPfbzRecordList(String sectionId, String expertId, String businessId, String businessType) {
        List<ExPingbiaoExpert> pingbiaoExpertList = exPingbiaoExpertMapper.selectByExpertIdAndBusinessIdList(expertId, com.google.common.collect.Lists.newArrayList(businessId));
        if (CollectionUtils.isNotEmpty(pingbiaoExpertList)) {
            List<ExPingbiaoExpertDetail> expertDetailList = exPingbiaoExpertDetailMapper.selectByExpertAndBusinessId(pingbiaoExpertList.get(0).getId(), "评分标准");
            return Result.ok(expertDetailList);
        }
        return Result.ok(Lists.newArrayList());
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<Boolean> complete(String bidSectionId, String userId) {
        ExPingbiaoExpertStage exPingbiaoExpertStage = exPingbiaoExpertStageService.selectBySectionId(bidSectionId);
        exPingbiaoExpertStage.setCompleteStatus(1);
        exPingbiaoExpertStage.setCompleteTime(new Date());
        exPingbiaoExpertStageService.updateById(exPingbiaoExpertStage);
        ExSection exSection = exSectionMapper.selectById(bidSectionId);
        exSection.setStatus("3");//评标结束
        exSectionMapper.updateById(exSection);
        LambdaQueryWrapper<ExTenderList> query = new LambdaQueryWrapper<ExTenderList>().eq(ExTenderList::getBidSectionId, bidSectionId);
        List<ExTenderList> exTenderLists = exTenderListService.list(query);
        ArrayList<ExTbcompanyScore> exTbcompanyScoreArrayList = new ArrayList<>();
        for (ExTenderList e : exTenderLists) {
            ExTbcompanyScore exTbcompanyScore = new ExTbcompanyScore();
            exTbcompanyScore.setBidSectionId(bidSectionId);
            exTbcompanyScore.setTenderListId(e.getId());
            exTbcompanyScore.setBidderUserId(e.getBidderUserId());
            exTbcompanyScore.setBidderName(e.getBidderName());
            exTbcompanyScore.setBusinessPartScore(BigDecimal.ZERO); //商务标得分
            exTbcompanyScore.setTechPartScore(BigDecimal.ZERO); //技术标得分
            exTbcompanyScore.setCompositeScore(BigDecimal.ZERO); //综合标得分
            exTbcompanyScore.setOtherScore(BigDecimal.ZERO); //其他得分
            exTbcompanyScore.setFinalScore(BigDecimal.ZERO); //最终得分
            exTbcompanyScore.setRank(1); //排名
            exTbcompanyScoreArrayList.add(exTbcompanyScore);
        }
        boolean result = exTbcompanyScoreService.saveBatch(exTbcompanyScoreArrayList);
        return Result.ok(result);
    }

    @Override
    public boolean getAllCmpleted(String bidSectionId, String id) {
        boolean result = false;
        ExSection exSection = exSectionMapper.selectById(bidSectionId);
        if(StringUtils.isBlank(exSection.getStatus())){
            return false;
        }
        if(!exSection.getStatus().equals("2")){
            return false;
        }
        List<ExPingbiaoSectionExpertConfig> expertConfigList = expertConfigMapper.selectByProjectAndSectionId(null, bidSectionId);
        ExPingbiaoExpertStage exPingbiaoExpertStage = exPingbiaoExpertStageMapper.selectBySectionId(bidSectionId);
        if(exPingbiaoExpertStage == null){
            return false;
        }
        List<ExTenderList> exTenderLists = exTenderListService.queryBySectionId(bidSectionId);
        //todo 每一个投标人   对每个节点  都需要评审完成 才行算通过（符合性审查中 如果有 不符合情况【组长确认过】， 该投标人  后面流程环节不再需要 评审，直接就算通过）
        ExZbwjBidEvaluationConfig evaluationConfig = evaluationConfigMapper.selectByBidSectionId(bidSectionId);
        List<ExZbwjBidEvaluationItem> evaluationItemList = evaluationItemMapper.selectByMainIdList(com.google.common.collect.Lists.newArrayList(evaluationConfig.getId()));
        //当前节点是否为最后一个节点
        int maxIndex = evaluationItemList.size() - 1;
        Optional<ExZbwjBidEvaluationItem> optionalExZbwjBidEvaluationItem = evaluationItemList.stream().filter(item -> item.getId().equals(exPingbiaoExpertStage.getBusinessId()) && item.getIndex().equals(maxIndex)).findFirst();
        if (optionalExZbwjBidEvaluationItem.isPresent() && optionalExZbwjBidEvaluationItem.get() != null) {
            LambdaQueryWrapper<ExPingbiaoExpert> query = new LambdaQueryWrapper<ExPingbiaoExpert>();
            query.eq(ExPingbiaoExpert::getBidSectionId, bidSectionId);
            query.eq(ExPingbiaoExpert::getBusinessId, optionalExZbwjBidEvaluationItem.get().getId());
            List<ExPingbiaoExpert> exPingbiaoExpertList = this.list(query);
            if(exPingbiaoExpertList.size() == expertConfigList.size()){//所有专家都已进行评标
                result = true;
            }
        }
        return result;
    }
}
